package com.xxx.kjds.config;


import com.xxx.kjds.config.intercepors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * webMvc配置
 */
@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    /**
     * 注入登录拦截器
     */
    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 注册资源拦截器
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    }

    /**
     * 注册登录拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").
                excludePathPatterns("/login/**", "/", "/register/**", "/js/**", "/images/**", "/css/**",
                        "/myplugs/**", "/res/**", "/skin/**", "/image/**", "/amazeui/**",
                        "/layui/**", "/richText/**", "/webuploader/**", "/font/**", "/.com/**");
    }

    /**
     * 注册视图拦截器
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/login");
    }
}
